package com.kanavi.fpm.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.kanavi.fpm.entity.AdsNucleicAcidRuleConfigEntity;
import com.kanavi.fpm.mapper.AdsNucleicAcidRuleConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping
@Slf4j
public class NucleicAcidRuleConfigController {

    @Autowired
    private AdsNucleicAcidRuleConfigMapper adsNucleicAcidRuleConfigMapper; // target目录下


    @RequestMapping("add")
    public void add() {
        ExcelReader reader = ExcelUtil.getReader(FileUtil.file("D:\\soft\\服务人员核酸检测频次要求.xls"),"统计");
        log.info(JSONUtil.toJsonStr(reader));
        reader.addHeaderAlias("责任部门","competentDeptStr");
        reader.addHeaderAlias("人员类别","categoryStr");
        reader.addHeaderAlias("人员代码","category");
        reader.addHeaderAlias("频次要求","frequency");
        reader.addHeaderAlias("赋灰码的核酸时限要求","nucleicAcidRule");
        List<AdsNucleicAcidRuleConfigEntity> excelEntities = reader.readAll(AdsNucleicAcidRuleConfigEntity.class);
        reader.close();
        adsNucleicAcidRuleConfigMapper.insertBatch(excelEntities);
    }
}
